package com.hs.gs.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.hs.gs.domain.Patrol;
import com.hs.gs.vo.PatrolOfDepartmentVO;

@RooWebScaffold(path = "patrols", formBackingObject = Patrol.class, exposeFinders = false)
@RequestMapping("/patrols")
@Controller
public class PatrolController {

	@RequestMapping(params = { "find=ByDate" }, method = RequestMethod.GET)
    public String dailyReport(@RequestParam("date") String sdate, Model uiModel) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date;
		try {
			date = sdf.parse(sdate);
	    	List<Patrol> patrols = Patrol.findPatrolsByPatrolDay(date).getResultList();
	    	List<PatrolOfDepartmentVO> vos = PatrolOfDepartmentVO.populate(patrols);
	    	uiModel.addAttribute("vos", vos);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//    	addDateTimeFormatPatterns(date);
        return "patrols/dailyReport";
    }

	@RequestMapping(params = { "find=ByDate", "form" }, method = RequestMethod.GET)
    public String dailyReportForm(Model uiModel) {
        return "patrols/dailyReport";
    }
}
